package com.senac.parser;

import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;

import com.senac.model.Disciplina;
import com.senac.model.Professor;

public class DisciplinaParser extends Parser<Disciplina> {
	
	
	public DisciplinaParser(ResultSet rs) {
		super(rs);
	}

	
	@Override
	public Disciplina parse() throws SQLException {
		
		Disciplina disciplina = new Disciplina();
//		disciplina.setId(rs.getInt("ID"));
//		disciplina.setNome(rs.getString("NOME"));
//		Professor p = new Professor();
//		p.setId(rs.getInt("ID_PROFESSOR"));
//		disciplina.setProfessor(p);
//		disciplina.setCargaHoraria(rs.getInt("CARGA_HORARIA"));
//		disciplina.setConteudo(rs.getString("CONTEUDO"));
		
		
		ResultSetMetaData md = getRs().getMetaData();
		
		for (int i = 1; i <= md.getColumnCount(); i++) {
			String columnName = md.getColumnName(i).toLowerCase();
			
			switch (columnName) {
			case "id":
				disciplina.setId(getRs().getInt(columnName));
				break;
			case "nome":
				disciplina.setNome(getRs().getString(columnName));
				break;
			case "id_professor":
				Professor p = new Professor();
				p.setId(getRs().getInt(columnName));
				disciplina.setProfessor(p);
				break;
			case "carga_horaria":
				disciplina.setCargaHoraria(getRs().getInt(columnName));
				break;
			case "conteudo":
				disciplina.setConteudo(getRs().getString(columnName));
				break;				
				
			default:
				break;
			}
		}
		
		return disciplina;

	}

}
